<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-setting"></i> 快速申请 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-date-picker v-model="query.time" class="mr10" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
        <el-input placeholder="请输入姓名查询" class="handle-input mr10" v-model="query.kw"></el-input>
        <el-button class="mr10" type="primary" icon="el-icon-search" @click="souClick">搜索</el-button>
      </div>
      <el-table :data="tableData" border class="table" style="width: 100%" ref="multipleTable" header-cell-class-name="table-header">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="姓名"></el-table-column>
        <el-table-column prop="phone" label="电话"></el-table-column>
        <el-table-column prop="quota" label="申请金额"></el-table-column>
        <el-table-column prop="cityName" label="办理城市"></el-table-column>
        <el-table-column prop="applyTime" label="创建时间"></el-table-column>
        <el-table-column fixed="right" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-setting" class="red" @click="delClick(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.page" :page-size="query.limit" :total="query.totalCount"
                       :pager-count="5" @current-change="PageChange" @prev-click="PageChange" @next-click="PageChange"></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { webDfastInit, webDfastDel } from '../../../api/index'
export default {
  data() {
    return {
      query: {
        page: 1,
        limit: 10,
        totalCount: 0,
        kw: '',
        time: [],
      },
      tableData: [],
    }
  },
  created() {
    this.getInit();
  },
  methods: {
    //初始化
    getInit() {
      webDfastInit({
        page: this.query.page,
        limit: this.query.limit,
        startTime: this.query.time ? this.query.time[0] : '',
        endTime: this.query.time ? this.query.time[1] : '',
        kw: this.query.kw,
      }).then(res => {
        if (res.code == 0) {
          this.tableData = res.recordList;
          this.query.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //序号
    tableIndex(index) {
      return (this.query.page - 1) * this.query.limit + index + 1;
    },
    //翻页
    PageChange(num) {
      this.query.page = num;
      this.getInit();
    },
    //搜索
    souClick() {
      this.query.page = 1;
      this.getInit();
    },
    //删除
    delClick(id) {
      webDfastDel({
        id: id
      }).then(res => {
        if (res.code == 0) {
          this.$message.success("删除成功");
          this.getInit();
        } else {
          this.$message(res.msg);
        }
      })
    },
  }
}
</script>
<style scoped>
.handle-input {
    width: 300px;
    display: inline-block;
}
</style>